package com.ysd.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.ChanPinFenLeiDaoImpl;
import com.ysd.dao.impl.JuTiShangPinDaoImpl;
import com.ysd.entity.ChanPinFenLei;
import com.ysd.entity.JuTiShangPin;

public class ProductsServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//产品分类
		ChanPinFenLeiDaoImpl chanPinFenLeiDao = new ChanPinFenLeiDaoImpl();
		List<ChanPinFenLei> chanPinFenLeiList = chanPinFenLeiDao.getChanPinFenLei();
		request.setAttribute("chanPinFenLeiList", chanPinFenLeiList);
		
		//根据产品分类id查询对应的产品
		int chanPinId = Integer.parseInt(request.getParameter("chanPinId"));
		JuTiShangPinDaoImpl juTiShangPinDao = new JuTiShangPinDaoImpl();
		List<JuTiShangPin> juTiShangPinList = juTiShangPinDao.getJuTiShangPinList(chanPinId);
		request.setAttribute("juTiShangPinList", juTiShangPinList);
		
		request.getRequestDispatcher("productlist.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
